import React, { useEffect, useState } from 'react'
import { useHistory } from 'react-router-dom'
import { GetFastApi } from '@/Api'
import { alertDispatch } from '@/utils'
import { connect } from 'react-redux'
import CheckLogin from '@/components/CheckLogin'
import Subject from '@/components/Subject'
import './Fast.less'

function Fast(props) {
    const [records, setRecords] = useState([])
    const history = useHistory()
    // eslint-disable-next-line
    useEffect(async () => {
        try {
            const res = await GetFastApi()
            const { records } = res.data
            if (res.errCode === 0) {
                setRecords(records)
            }

        } catch (err) {
            if (err) {
                if (err.response.data.errCode === 1002) {
                    props.error(err.response.data.message)
                    history.push('/login')
                }
            }
        }
    }, [history, props])
    return (
        <div>
            <div className="subject-list">
                {
                    records.map(item => {
                        return <Subject key={item.actionCode} data={item}></Subject>
                    })
                }
            </div>
        </div>
    )
}
export default connect(null, alertDispatch)(CheckLogin(Fast))